﻿

function applyCssToValidate(elements,isInline)
{
    //This is to display asterix(*) for all the mandatory fields where class = "manadatory"
    //$(".mandatory").append("<span style='padding-left:2px;color:red;'> *</span>").next().css('color', 'red');
    
    //This is to mask the input accordingly.
//    $.mask.definitions['~'] = "[+-]";
//    $(".form input.mskDate").mask("99/99/9999");
//    $(".form input.mskPhone").mask("(999) 999-9999");
//    $(".form input.mskEmpID").mask("aa-9999");

    var selector="";        
    for (i=0;i<elements.length;i++)    {
        if(i>0) selector=selector +  ","
        selector=selector+ "#" + elements[i];        
    }       
//    $("div").not(selector).find(":input").addClass("ignore");
//    $(selector).find(":input").removeClass("ignore");
    validateForm(isInline);
}

function validateForm(isInline)
{  
        //Validate the password input with class="required password"
      
        var validator = $("form").validate({
		ignore: ".ignore",
		ignoreTitle: true,

			
      // the errorPlacement has to take the table layout into account
            errorPlacement: function(error, element) {          
            
             
            },
           
       
		// specifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			alert("submitted!");
		},
 		invalidHandler: function(form, validator) {
			 var message ="";
			        for (i=0;i<validator.numberOfInvalids();i++)
			        {
			           // message = getErrorMessage(validator.errorList[i],validator.errorList[i].element.id);
				        var selector = "label[for='" + validator.errorList[i].element.id + "']";
				        if(validator.errorList[i].message.indexOf("required") > 0)
				        {				          
				              message = message + $(selector).text() + " is required\n";
				              message=message.replace("*", "");
				        }
				        else
				            message = message + validator.errorList[i].message + "\n";
			        }
      			    alert(message);
      		
       }
	});	 
}


